<?php

namespace common\models\DAO;

use Yii;
use yii\helpers\ArrayHelper;

/**
 * This is the model class for table "{{%article_type}}".
 *
 * @property integer $id
 * @property string $typeName
 * @property integer $parentID
 * @property string $type
 * @property string $createTime
 * @property string $updateTime
 * @property integer $sort
 * @property string $content
 * @property integer $isMenu
 */
class ArticleType extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%article_type}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['parentID', 'createTime', 'updateTime', 'sort'], 'integer'],
            [['content'], 'string'],
            [['typeName'], 'string', 'max' => 30],
            [['type'], 'string', 'max' => 20],
        ];
    }

    public function scenarios()
    {
        return [
            'default' => [],
            'add' => ['parentID', 'typeName', 'type', 'sort', 'content', 'isMenu'],
            'edit' => ['parentID', 'typeName', 'type', 'sort', 'content', 'isMenu'],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => '主键id',
            'typeName' => '分类名称',
            'parentID' => '上级分类',
            'type' => '类型',
            'createTime' => '创建时间',
            'updateTime' => '更新时间',
            'sort' => '排序',
            'content' => '分类内容',
            'isMenu' => '是否为导航'
        ];
    }

    public function beforeSave($insert)
    {
        if($insert){
            $this->createTime = time();
        }
        $this->updateTime = time();
        return parent::beforeSave($insert); // TODO: Change the autogenerated stub
    }
}
